﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonica.Utility;
using System.Windows.Forms;

namespace FileTags
{
    public class ContextMenuHelper
    {
        private ShellContextMenu _contextMenu;
        private const string _menuName = "Tags managment";

        public void CheckContextMenu()
        {
            _contextMenu = new ShellContextMenu("ozlevka.FileTags");
            if (!MenuExists())
            {
                string command = Application.ExecutablePath + @" %1";

                _contextMenu.SetContextMenuItem(ShellContextMenu.ContextMenuFor.ALLFILES, _menuName, command, string.Empty);
            }
        }

        private bool MenuExists()
        {
            string command;
            string menuText;

            _contextMenu.GetContextMenuItem(ShellContextMenu.ContextMenuFor.ALLFILES, out menuText, out command, string.Empty);

            if (string.IsNullOrEmpty(menuText) && string.IsNullOrEmpty(command))
            {
                return false;
            }

            return true;
        }
    }
}
